import * as crypto from 'crypto';
import { ParamsNotValidError } from '@jingli/error';

export function md5(plainText: string): string { 
    if (!plainText) { 
        throw new ParamsNotValidError('plainText');
    }
    return crypto.createHash('md5').update(plainText).digest('hex');
}

export function genToken(username: string, pwd: string, timestamp: string): string{ 
    return md5([username, pwd, timestamp].join('|')) + timestamp;
}